package com.example.webdome.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.webdome.mapper.UrlNumberMapper;
import com.example.webdome.pojo.UrlNumber;
import com.example.webdome.service.UrlNumberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UrlNumberServiceImpl extends ServiceImpl<UrlNumberMapper, UrlNumber> implements UrlNumberService {
    @Override
    public int getUrlNumber(String url) {
        QueryWrapper<UrlNumber> wrapper = new QueryWrapper<>();
        wrapper.eq("url",url);

        try {
            // 执行查询
            UrlNumber urlNumber = this.getOne(wrapper);

            if (urlNumber != null) {
                // 查询成功，返回结果
                return urlNumber.getNumber();
            } else {
                // 查询结果为空
                return 0;
            }
        } catch (Exception e) {
            log.error("加载失败", e);
            return 0;
        }
    }
}
